/**
 * jims
 */
package com.jims.master.modules.nurse.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jims.master.common.data.StringData;
import com.jims.master.common.persistence.Page;
import com.jims.master.common.web.BaseController;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.modules.nurse.entity.NurseTempDetailInfo;
import com.jims.master.modules.nurse.service.NurseTempDetailInfoService;

import java.util.List;

/**
 * 主要护理项目Controller
 * @author CTQ
 * @version 2017-06-01
 */
@Controller
@RequestMapping(value = "${adminPath}/nurse/nurseTempDetailInfo")
public class NurseTempDetailInfoController extends BaseController {

	@Autowired
	private NurseTempDetailInfoService nurseTempDetailInfoService;
	
	@ModelAttribute
	public NurseTempDetailInfo get(@RequestParam(required=false) String id) {
		NurseTempDetailInfo entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = nurseTempDetailInfoService.get(id);
		}
		if (entity == null){
			entity = new NurseTempDetailInfo();
		}
		return entity;
	}
	
	@RequiresPermissions("user")
	@RequestMapping(value = {"index", ""})
	public String list(NurseTempDetailInfo nurseTempDetailInfo, Model model) {
		nurseTempDetailInfo.updateOrgId();
		List<NurseTempDetailInfo> list = nurseTempDetailInfoService.findList(nurseTempDetailInfo);
		model.addAttribute("list", list);
		return "modules/nurse/nurseTempDetailInfoIndex";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "form")
	public String form(NurseTempDetailInfo nurseTempDetailInfo, Model model) {
		model.addAttribute("nurseTempDetailInfo", nurseTempDetailInfo);
		return "modules/nurse/nurseTempDetailInfoForm";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "save")
	@ResponseBody
	public StringData save(NurseTempDetailInfo nurseTempDetailInfo, Model model) {
	    StringData data=new StringData();
		int i=nurseTempDetailInfoService.save(nurseTempDetailInfo);
        if(i>0){
            data.setCode("success");
            data.setData("保存主要护理项目成功");
        }else{
            data.setCode("error");
            data.setData("保存主要护理项目失败");
        }
        return data;
	}
	@RequiresPermissions("user")
	@RequestMapping(value = "delete")
	@ResponseBody
	public StringData delete(NurseTempDetailInfo nurseTempDetailInfo) {
	    StringData data=new StringData();
		int i=nurseTempDetailInfoService.delete(nurseTempDetailInfo);
        if(i>0){
            data.setCode("success");
            data.setData("删除主要护理项目成功");
        }else{
            data.setCode("error");
            data.setData("删除主要护理项目失败");
        }
		return data;
	}

}